using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using TMPro;
using Features;

public class SpriteText : MonoBehaviour
{
    public TMP_Text text;
    public float floatTime;
    public float exitTime;

    public void Init(float damage)
    {
        if(damage != 5)
        text.text = "-" + damage.ToString();
        text.color = Color.white;
        StartCoroutine(FloatCoroutine(0.5f));
    }

    public void Init(string txt, Color color)
    {
        text.text = txt;
        text.color = color;
        StartCoroutine(FloatCoroutine(-1f));
    }

    IEnumerator FloatCoroutine(float distance)
    {
        yield return new WaitForSeconds(Random.Range(0,0.3f));
        Vector3 dis = new Vector3(0f, -distance, -Mathf.Sqrt(3f) / 2f) * 2f;
        transform.DOMove(transform.position + dis, floatTime).SetEase(Ease.OutQuad);
        yield return new WaitForSeconds(floatTime - exitTime);

        text.DOFade(0, exitTime);

        yield return new WaitForSeconds(exitTime);

        Destroy(gameObject);
    }
}
